package com.example;
import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class CookieTest extends HttpServlet {
@Override



public void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	// TODO Auto-generated method stub
	exec (req,resp);
}

	public void doget(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{
		exec (req,res);
		
	}
	
	public void exec(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
	String name = req.getParameter("userName");
		Cookie cookie = new Cookie("userName", name);
		cookie.setMaxAge(30*60);
		res.addCookie(cookie);
		
	RequestDispatcher view = req.getRequestDispatcher("getCookie.jsp");
		view.forward(req, res);
		
	}
}
